﻿Imports Oracle.DataAccess.Client
Imports System.Data.OleDb

Partial Class DenunciasCargar
    Inherits System.Web.UI.Page
    Private x As Integer
    Private Cmd As OracleCommand
    Private dt As Data.DataTable
    Private Cnx As OracleConnection
    Private oradb As String = "Data Source=XE;User Id=SIRA;Password=SIRA123;"
    Private Sql As String
    Private Aux As String
    Private dr As OracleDataReader

    Protected Sub LiberarRecursos()
        Cnx.Close()
        Cmd.Dispose()
        Cnx.Dispose()
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        lblUserNick.Text = Session("VarSessionUserNick")
        lblUserNombre.Text = Session("VarSessionUserNombre")
        lblUserIdCategoria.Text = Session("VarSessionUserIdCategoria")
        lblUserCategoria.Text = Session("VarSessionUserCategoria")
        lblUserIdComisaria.Text = Session("VarSessionUserIdComisaria")
        lblUserComisaria.Text = Session("VarSessionUserComisaria")
        lblUserIdNodo.Text = Session("VarSessionUserIdNodo")
        lblUserNodo.Text = Session("VarSessionUserNodo")
        lblUserIdUsuario.Text = Session("VarSessionUserIdUsuario")
        lblFechaAlta.Text = Today
    End Sub

    Protected Sub btnAceptar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAceptar.Click
        If Page.IsValid Then
        Else
            labelMessage.Text = "Error en carga de datos - Proceso btnAceptar_Click - CargarDenuncia.aspx"
            Exit Sub
        End If
        If txtObservaciones.Text.Length = 0 Then txtObservaciones.Text = "-"
        Cnx = New OracleConnection(oradb)
        Cnx.Open()
        Try
            Sql = "INSERT INTO Denuncias (IdComisaria_Alta, IdNodo_Alta, IdUsuario_Alta, " & _
                  "Patente, Fecha_Alta, Captura, Recuperado, Observaciones) VALUES (" & _
                  "'" & Session("VarSessionUserIdComisaria") & "'," & _
                  "'" & Session("VarSessionUserIdNodo") & "'," & _
                  "'" & Session("VarSessionUserIdUsuario") & "'," & _
                  "'" & txtPatente.Text & "'," & _
                  "'" & lblFechaAlta.Text & "'," & _
                  "'S'," & _
                  "'N'," & _
                  "'" & txtObservaciones.Text & "')"
            Cmd = New OracleCommand(Sql, Cnx)
            Cmd.ExecuteNonQuery()
        Catch ex As Exception
            MsgBox("No puedo Agregar (INSERT INTO) tabla Denuncias " & vbCrLf & ex.Message, MsgBoxStyle.Critical, _
                   "Error proceso btnAceptar_Click panel Agregar - CargarDenuncia.aspx")
        Finally
        End Try
        LiberarRecursos()
        MsgBox("Cargado con exito " & vbCrLf & "Patente " & txtPatente.Text, MsgBoxStyle.OkOnly, _
        "Carga exitosa")
        LimpiarPanelCargar()

    End Sub
    Protected Sub LimpiarPanelCargar()
        txtPatente.Text = ""
        txtObservaciones.Text = ""
    End Sub

    Protected Sub btnSalir_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSalir.Click
        PanelAgregar.Visible = False
    End Sub
End Class
